package com.pccc.batch.config.remotepartition.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.batch.integration.partition.StepExecutionRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.pccc.batch.config.remotepartition.asyn.AsynStepEvent;
import com.pccc.batch.config.remotepartition.service.PublishEventService;

@RestController
public class RemoteStepController {

	@Autowired
	private PublishEventService publish;
	
	@RequestMapping(value="/store",consumes="application/x-java-serialized-object",method=RequestMethod.POST,produces=MediaType.TEXT_PLAIN_VALUE)
	public String stepExection(@RequestBody StepExecutionRequest stepRequest,HttpServletRequest request) {
		AsynStepEvent event = new AsynStepEvent(RemoteStepController.class);
		event.setStepRequest(stepRequest);
		event.setCorrelationId(request.getHeader("correlationId"));
		event.setSequenceNumber(request.getHeader("sequenceNumber"));
		event.setSequenceSize(request.getHeader("sequenceSize"));
		publish.sendStep(event);
		return "success";
	}
	
}
